package manager;

import java.util.ArrayList;

import manager.interfaces.ICustomerManager;
import vo.Customer;
import exception.NotFoundException;

public class CustomerManager implements ICustomerManager{

	private static CustomerManager customerManager;
	ArrayList<Customer> customerList;

	private CustomerManager() {
		customerList = new ArrayList<Customer>();		
	}

	public static CustomerManager getInstance() {
		if(null == customerManager) {
			return new CustomerManager();
		} else {
			return customerManager;
		}		
	}



	@Override
	public Customer findCustomer(int customId) throws NotFoundException  {

		Customer seekedCustomer = null;


		for(int i = 0; i < customerList.size(); ++i) {

			Customer customer = customerList.get(i);

			if(customId == customer.getId()){
				seekedCustomer = customer;
			}
		}

		if(null == seekedCustomer) {
			throw new NotFoundException();
		}
		

		return seekedCustomer;
	}

	@Override
	public boolean unregistCustomer(Customer customer) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean registCustomer(Customer customer) {
		
		try{
			customerList.add(customer);
		} catch(Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

}
